/*
 * strtime.c
 *
 *  Created on: 2013-12-17
 *      Author: panhong
 */
#include <stdio.h>
#include <stdarg.h>
#include "fire_time.h"

time_t GetMiddleNt(time_t ltime)
{
	struct tm *pstTm;
	pstTm = localtime_r(&ltime);
	pstTm->tm_hour=0;
	pstTm->tm_min=0;
	pstTm->tm_sec=0;
	return mktime(pstTm);
}



char *GetCurShortDateStr(void)
{

	time_t mytime = time(NULL);

	return GetShortDateStr(&mytime);

}

char *GetShortDateStr(const time_t *mytime)
{
	static char s[50];

	struct tm curr = *localtime_r(mytime);
	if (curr.tm_year > 50)
		sprintf(s, "%04d%02d%02d",
					curr.tm_year+1900, curr.tm_mon+1, curr.tm_mday);
	else
		sprintf(s, "%04d%02d%02d",
					curr.tm_year+2000, curr.tm_mon+1, curr.tm_mday);

	return s;
}

char *GetCurDateStr(void)
{
	time_t mytime = time(NULL);

	return GetDateStr(&mytime);
}

char *GetDateStr(const time_t *mytime)
{
	static char s[50];

	struct tm curr = *localtime_r(mytime);

	if (curr.tm_year > 50)
		sprintf(s, "%04d-%02d-%02d",
					curr.tm_year+1900, curr.tm_mon+1, curr.tm_mday);
	else
		sprintf(s, "%04d-%02d-%02d",
					curr.tm_year+2000, curr.tm_mon+1, curr.tm_mday);

	return s;
}

char *GetCurDateTimeStr(void)
{
	time_t mytime = time(NULL);

	return GetDateTimeStr(&mytime);
}

char *GetDateTimeStr(const time_t *mytime)
{
	static char s[50];
	struct tm curr = *localtime_r(mytime);

	if (curr.tm_year > 50)
		sprintf(s, "%04d-%02d-%02d %02d:%02d:%02d",
					curr.tm_year+1900, curr.tm_mon+1, curr.tm_mday,
					curr.tm_hour, curr.tm_min, curr.tm_sec);
	else
		sprintf(s, "%04d-%02d-%02d %02d:%02d:%02d",
					curr.tm_year+2000, curr.tm_mon+1, curr.tm_mday,
					curr.tm_hour, curr.tm_min, curr.tm_sec);

	return s;
}

char *GetCurShortDateTimeStr(void)
{
	time_t mytime = time(NULL);

	return GetShortDateTimeStr(&mytime);
}

char *GetShortDateTimeStr(const time_t *mytime)
{
	static char s[50];
	struct tm curr = *localtime_r(mytime);

	if (curr.tm_year > 50)
		sprintf(s, "%04d%02d%02d%02d%02d%02d",
					curr.tm_year+1900, curr.tm_mon+1, curr.tm_mday,
					curr.tm_hour, curr.tm_min, curr.tm_sec);
	else
		sprintf(s, "%04d%02d%02d%02d%02d%02d",
					curr.tm_year+2000, curr.tm_mon+1, curr.tm_mday,
					curr.tm_hour, curr.tm_min, curr.tm_sec);

	return s;
}

char* GetCurTimeStr(void)
{
	time_t mytime = time(NULL);

	return GetTimeStr(&mytime);
}

char* GetTimeStr(const time_t *mytime)
{
	static char s[50];
	struct tm curr = *localtime_r(mytime);

	sprintf(s, "%02d:%02d:%02d",
				curr.tm_hour, curr.tm_min, curr.tm_sec);

	return s;
}
char *GetCurShortTimeStr(void)
{
	time_t mytime = time(NULL);

	return GetShortTimeStr(&mytime);
}

char *GetShortTimeStr(const time_t *mytime)//205301
{
	static char s[50];
	struct tm curr = *localtime_r(mytime);

	sprintf(s, "%02d%02d%02d",
				curr.tm_hour, curr.tm_min, curr.tm_sec);

	return s;
}

